<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$escortCategoryId = getKeyOfArray( getSiteCategoryBaseOnSiteSetting() );
	
	$current_dbprefix = $this->db->dbprefix;
	$this->db->set_dbprefix('default_');
	
	$page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 0 ;
	$records_per_page = RECORD_PER_PAGE; 
 
	//$allResult = $this->db->where('published',1)->where("places_list_ids_contract != ''")->order_by('times_visited','desc')->get(TBL_ESCORT)->result();	
	$allResult = $this->db->where( array('published'=>1, "places_list_ids_contract !="=> '', 'escort_category_id'=>$escortCategoryId))->order_by('times_visited','desc')->get(TBL_ESCORT)->result();	
	
	$total = count($allResult);
	
	$pagination = create_pagination( 
								$uri = 'home/top_escorts/?async=true', 
								$total_rows = $total , 
								$limit= $records_per_page,
								$uri_segment = 0,
								TRUE, TRUE 
							);

	$records = $this->db->where( array('published'=>1, "places_list_ids_contract !="=> '', 'escort_category_id'=>$escortCategoryId))->order_by('times_visited','desc')
			->limit($records_per_page, $page )->get(TBL_ESCORT)->result();
			
	$measureOptionArray = getMeasureOptionData_ioc();
	 
	$_SESSION['backURL'] = str_replace('async','sync',fullURL() );
	
	$_SESSION['pagination_result'] = array();
	$i = 1;
	foreach($allResult as $item){
		$_SESSION['pagination_result'][$item->id] = array( $i++ => $item->id);
	}
	$_SESSION['totalRESULTsearch'] = $total;
	
	unset($_SESSION['location_ids']);
?>


<?php $this->db->set_dbprefix($current_dbprefix);?>	

<div class="home-escort-list">
		<?php $this->load->view("home/display_escort_info", array('records'=>$records,'item_per_row'=>4,'page'=>'TOP_ESCORT') ) ;?>
		<div class="clear"></div>
		<div class="pagging">
			<div id="browse_escort">
				<?php echo $pagination['links'];?>
			</div>
		</div>
	</div>
	